package com.neuedu.web;

import com.neuedu.pojo.Demo;
import com.neuedu.pojo.Result;
import com.neuedu.service.DemoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 屈博
 * @email qubome@aliyun.com
 * @Date 2024/6/4 21:25
 */
@RestController
@RequestMapping("/demo")
@Tag(name="xxxx接口")
public class DemoController {
    @Resource   // 注入service
    private DemoService demoService;

    /**
     * 根据id查询 Demo 对象
     */
    @GetMapping("/byId")
    @Operation(summary = "根据ID获取xxxx信息")
    public Result<Demo> getById(@Parameter(description="xxxID") @RequestParam("id")Integer id){
        return Result.success(this.demoService.getById(id) , "查询成功");
    }

    /**
     * 查询所有数据
     */
    @GetMapping("/all")
    @Operation(summary = "获取xxxx信息列表")
    public Result<List<Demo>> getAll(){
        return Result.success(this.demoService.list() , "查询成功");
    }

    /**
     * 分页和条件查询
     * @return
     */
    @GetMapping("/page")
    @Operation(summary = "分页与条件查询xxxx信息列表")
    public Result<List<Demo>> getPage(@RequestParam(name="currentPage",defaultValue = "1")Integer currentPage,
                                      @RequestParam(name="pageSize",defaultValue = "10")Integer pageSize,
                                      // 需要条件查询的字段数据
                                      @RequestParam(name="name",defaultValue = "",required = false)String name){
        return this.demoService.getPage(currentPage,pageSize,name);
    }
    /**
     * 添加数据
     */
    @PostMapping("/add")
    @Operation(summary = "添加xxxx信息数据")
    public Result<Void> addDemo(@RequestBody Demo demo){
        return this.demoService.addDemo(demo);
    }
    /**
     * 修改数据
     */
    @PutMapping("/update")
    @Operation(summary = "修改xxxx信息数据")
    public Result<Void> updateDemo(@RequestBody Demo demo){
        return this.demoService.updateDemo(demo);
    }
    /**
     * 删除数据
     */
    @DeleteMapping("/delete")
    @Operation(summary = "删除xxxx信息数据")
    public Result<Void> deleteDemo(Integer id){
        return this.demoService.deleteDemo(id);
    }
}
